import { defineStore } from 'pinia'
import { loginAPI } from '@/api/loginAPI'
import { ref } from 'vue'
import { ElMessage } from 'element-plus'

export const useUserStore = defineStore('user', () => {
    const userInfo = ref({})

    // 登录
    const login = async (form) => {
        const { data: res } = await loginAPI(form)
        if (res.meta.status !== 200) return ElMessage.error(res.meta.msg)
        console.log(res.data);
        userInfo.value = res.data
    }

    // 退出登录
    const logout = ()=>{
        userInfo.value = []
    }

    return {
        userInfo,
        login,
        logout
    }
}, {
    persist: true,
})